package com.gxa.employment.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;


/**
 * @Description: 日志记录
 * @Author:
 * @DateTime: 2025/3/6 12:33
 **/
//@Aspect
@Slf4j
//@Component
public class LogAspect {
    /**
     * 设置切点
     */
    @Pointcut("execution(* com.baomidou.mybatisplus.extension.service.IService+.*(..)) || " +
            "execution(* com.baomidou.mybatisplus.extension.service.impl.ServiceImpl+.*(..))")
    public void pointcut(){}

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        try {
            Object[] args = joinPoint.getArgs();
            Signature signature = joinPoint.getSignature();
            log.info("==================== 方法开始执行 ====================");
            log.info("方法的签名:{}",signature);
            log.info("方法的参数:{}",args);
            Object proceed = joinPoint.proceed(args);
            log.info("方法的返回值:{}",proceed);
            log.info("==================== 方法执行结束 ====================\n");
            return proceed;
        } catch (Throwable e) {
            log.info("==================== 方法执行异常结束 ====================\n");
            throw e;
        }
    }
}
